home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 129 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.5 KB

  1. Path: mujibur.inmind.com!usenet
  2. From: mfinney@inmind.com
  3. Newsgroups: comp.std.c
  4. Subject: Re: Help, best way to compare doubles
  5. Date: 17 Jan 1996 21:41:42 GMT
  6. Organization: In Mind, Inc.
  7. Message-ID: <4djqem$9th@mujibur.inmind.com>
  8. References: <4d1k09$aqq@mercury.IntNet.net> <4dbos6$o7q@umbc9.umbc.edu> <mlK/wQ9ytpDN084yn@csn.net>
  9. Reply-To: mfinney@inmind.com
  10. NNTP-Posting-Host: finneyman.inmind.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <mlK/wQ9ytpDN084yn@csn.net>, thads@csn.net (Thad Smith) writes:
  14. >In article <4ddev4$1vg@stingray.mcnc.org>,
  15. >coats@mcnc.org (Carlie Coats) wrote:
  16. >
  17. >>>14.5:    What's a good way to check for "close enough" floating-point
  18. >>>    equality?
  19. >
  20. >> A safer test is of the form
  21. >>
  22. >>    | a - b | / sqrt( a^2 + b^2 + delta ) < epsilon
  23. >
  24. >This criteria, plus the squared version which uses squares, seems
  25. >to be too much effort with no payback.
  26.  
  27. Check out "The Art of Computer Programming" by Donald Knuth,
  28. Volume 2 "Seminumerical Alogrithms" starting on page 213 (2nd
  29. edition) the section "4.2.2 Accuracy of Floating Point Arithmetic".
  30.  
  31. Knuth expounds on a bit of theory (easily followed) and the winds
  32. up with very precise methods for floating point comparision and
  33. the properties that hold.  You really need to read the section to
  34. fully understand the formulae.  But it seems to be reasonably
  35. definitive, outside of possible special application considerations.
  36.  
  37. BTW, none of the methods suggested so far are the ones that
  38. Knuth recommends.
  39.  
  40.  
  41. Michael Lee Finney
  42.  
  43.